﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using WebManager;

namespace BaoJian.WebManager.Function.ExProduct
{
    public partial class Rank : System.Web.UI.Page
    {
        private string ColumnID = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            ColumnID = HttpContext.Current.Request.QueryString["oid"];
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        protected void New_Click(object sender, EventArgs e)
        {
            string url = URLUtility.UrlBase + "/WebManager/Function/ExProduct/rank/RankNew.aspx?ColumnID=" + ColumnID;
            Page.Response.Redirect(url);
        }

        protected void Edit_Click(object sender, EventArgs e)
        {
            string sel = HttpContext.Current.Request.Form["selectCB"];
            if (sel == null)
            {
                return;
            }
            string[] sels = sel.Split(',');
            if (sels.Length > 1)
            {
                LYQ.MessageBox.Show(Page, "每次只能编辑一篇文章");
                return;
            }

            string url = URLUtility.UrlBase + "/WebManager/Function/ExProduct/rank/RankEdit.aspx?OID=" + sels[0] + "&ColumnID=" + ColumnID; ;
            Page.Response.Redirect(url);
        }

        protected void Delete_Click(object sender, EventArgs e)
        {
            string sel = HttpContext.Current.Request.Form["selectCB"];
            if (sel == null)
            {
                return;
            }
            LYQ.BLL.Rank bll = new LYQ.BLL.Rank();
            string[] sels = sel.Split(',');
            for (int i = 0; i < sels.Length; i++)
            {
                bll.Delete(new Guid(sels[i]));
            }

            GridView1.PageIndex = 0;
            BindData();
        }

        private void BindData()
        {
            LYQ.BLL.Rank bll = new LYQ.BLL.Rank();
            DataSet ds = bll.GetList(" [PCatalog]='" + ColumnID + "' ORDER BY [SID] asc");

            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
        }

       
    }
}
